/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.alanis.gui;

import cl.alanis.business.VentaBusiness;
import cl.alanis.dto.StockDto;
import cl.alanis.dto.VentaDto;
import cl.alanis.exception.StockNoExisteException;
import cl.alanis.exception.StockVendidoException;
import cl.alanis.util.AlanisLog;
import java.util.Date;
import javax.swing.table.DefaultTableModel;
import org.apache.log4j.Logger;

/**
 *
 * @author Pía
 */
public class VentaGui extends javax.swing.JDialog {
    Double sumaIva=new Double(0);
    Double sumaTotalIva=new Double(0);
    Double sumaTotalSinIva=new Double(0);
    Double sumaTotalGeneral=new Double(0);
    Logger logger=AlanisLog.obtenerLogger(VentaGui.class);
    /**
     * Creates new form VentaGui
     */
    public VentaGui() {
        this.setModal(true);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtCodigoProducto1 = new javax.swing.JTextField();
        bttIngresarCodigoVenta = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblListaProductoVenta = new javax.swing.JTable();
        lblErrorVenta = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblValorDescuento = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        lblTotalConIva = new javax.swing.JLabel();
        lblIva = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lblTotalProductoVenta = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        lblTotalSinIva = new javax.swing.JLabel();
        lblTotalGeneral = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cmbDescuento = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        bttLimpiarVenta = new javax.swing.JButton();
        bttCancelarVenta = new javax.swing.JButton();
        byyAceptarVenta = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
        setForeground(new java.awt.Color(255, 51, 102));
        setModalExclusionType(java.awt.Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);

        bttIngresarCodigoVenta.setText("Buscar");
        bttIngresarCodigoVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttIngresarCodigoVentaActionPerformed(evt);
            }
        });

        tblListaProductoVenta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código Stock", "Código Proveedor", "Descripción", "Aplicación", "Marca Auto", "Año Auto", "País Origen", "Fabricante", "Valor S/IVA", "Iva", "Valor Total"
            }
        ));
        jScrollPane1.setViewportView(tblListaProductoVenta);

        lblErrorVenta.setForeground(new java.awt.Color(255, 51, 51));
        lblErrorVenta.setText("-");

        jLabel10.setText("- NUEVA VENTA -");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar", "Código Producto", "Código Proveedor" }));

        jLabel4.setText("Resultados:");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(255, 0, 102), null, null), "Información de la Venta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Consolas", 1, 12), new java.awt.Color(0, 0, 204))); // NOI18N

        jLabel2.setText("Total General");

        jLabel5.setText("Total Sin IVA");

        jLabel7.setText("$");

        lblValorDescuento.setText("-");

        jLabel20.setText("$");

        jLabel19.setText("Valor Descuento");

        lblTotalConIva.setText("-");

        lblIva.setText("-");

        jLabel16.setText("Total con IVA");

        jLabel14.setText("$");

        jLabel15.setText("$");

        lblTotalProductoVenta.setText("-");

        jLabel13.setText("IVA");

        lblTotalSinIva.setText("-");

        lblTotalGeneral.setText("-");

        jLabel11.setText("Total de Productos:");

        jLabel8.setText("$");

        cmbDescuento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0%", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%", "10%", "11%", "12%", "13%", "14%", "15%", "16%", "17%", "18%", "19%", "20%", "21%", "22%", "23%", "24%", "25%", "26%", "27%", "28%", "29%", "30%" }));
        cmbDescuento.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbDescuentoItemStateChanged(evt);
            }
        });
        cmbDescuento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbDescuentoActionPerformed(evt);
            }
        });

        jLabel3.setText("Descuento");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(47, 47, 47)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(lblTotalGeneral))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel20)
                                .addGap(18, 18, 18)
                                .addComponent(lblValorDescuento))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel13)
                                .addComponent(jLabel16))
                            .addGap(47, 47, 47)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel14)
                                    .addGap(18, 18, 18)
                                    .addComponent(lblTotalConIva))
                                .addComponent(cmbDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(1, 1, 1)
                                    .addComponent(jLabel11)
                                    .addGap(18, 18, 18)
                                    .addComponent(lblTotalProductoVenta))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addGap(50, 50, 50)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel15)
                                        .addComponent(jLabel7))))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblTotalSinIva)
                                .addComponent(lblIva))))
                    .addComponent(jLabel3))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lblTotalProductoVenta))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTotalSinIva)
                        .addComponent(jLabel7)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(lblIva))
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jLabel14)
                    .addComponent(lblTotalConIva))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cmbDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel20)
                        .addComponent(lblValorDescuento))
                    .addComponent(jLabel19))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(lblTotalGeneral))
                    .addComponent(jLabel2))
                .addContainerGap())
        );

        bttLimpiarVenta.setText("Limpiar");
        bttLimpiarVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttLimpiarVentaActionPerformed(evt);
            }
        });

        bttCancelarVenta.setText("Cancelar");
        bttCancelarVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttCancelarVentaActionPerformed(evt);
            }
        });

        byyAceptarVenta.setText("Aceptar");
        byyAceptarVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                byyAceptarVentaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(txtCodigoProducto1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(bttIngresarCodigoVenta))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(130, 130, 130)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bttCancelarVenta)
                                    .addComponent(byyAceptarVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(bttLimpiarVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblErrorVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 967, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 20, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel10)
                .addGap(471, 471, 471))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCodigoProducto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bttIngresarCodigoVenta)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(88, 88, 88)
                        .addComponent(lblErrorVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addComponent(byyAceptarVenta)
                                .addGap(18, 18, 18)
                                .addComponent(bttCancelarVenta)
                                .addGap(18, 18, 18)
                                .addComponent(bttLimpiarVenta))
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(78, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbDescuentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbDescuentoActionPerformed
        
    }//GEN-LAST:event_cmbDescuentoActionPerformed

    private void byyAceptarVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_byyAceptarVentaActionPerformed
        
        VentaBusiness business = new VentaBusiness();
        lblErrorVenta.setText("----");
        DefaultTableModel model = (DefaultTableModel) tblListaProductoVenta.getModel();
        String temp = (String) cmbDescuento.getSelectedItem();
        String porcentajeStr = temp.substring(0, temp.length() - 1);
        Float porcentaje = Float.valueOf(porcentajeStr) / 100;
        StockDto[] stocks=new StockDto[model.getRowCount()];
        VentaDto venta=new VentaDto();       
        venta.setDescuento(porcentaje);
        venta.setFechaVenta((new Date()).getTime());
        venta.setValorTotal(Math.ceil(Double.valueOf(lblTotalGeneral.getText())));
        for(int i=0;i<model.getRowCount();i++){
           stocks[i]=new StockDto();
           stocks[i].setCodStock(model.getValueAt(i, 0).toString());
        }
        try {
            business.generaVenta(venta,stocks);
        } catch (Exception ex) {
            logger.error("Error:"+ex.getMessage());
            lblErrorVenta.setText(ex.getMessage());
        }
        this.dispose();
    }//GEN-LAST:event_byyAceptarVentaActionPerformed

    private void bttIngresarCodigoVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttIngresarCodigoVentaActionPerformed
        lblErrorVenta.setText("----");
        DefaultTableModel model = (DefaultTableModel) tblListaProductoVenta.getModel();
        VentaBusiness business = new VentaBusiness();
        StockDto stock=new StockDto();
        boolean sw=false;
        
        stock.setCodStock(txtCodigoProducto1.getText());
        try {
            for(int i=0;i<model.getRowCount();i++){
                if(((Long)model.getValueAt(i, 0)).equals(stock.getCodStock()))
                    sw=true;
            }
            if(sw){
                lblErrorVenta.setText("El codigo "+stock.getCodStock()+ " ya fue ingresado en esta venta");
            }
            else{
                Object[] fila=business.obtenerFilaTablaVenta(stock);
                model.addRow(fila);
                sumaIva+=Double.valueOf(fila[3].toString());
                sumaTotalSinIva+=Double.valueOf(fila[2].toString());
                sumaTotalIva+=Double.valueOf(fila[4].toString());
                lblIva.setText(String.valueOf(sumaIva));
                lblTotalSinIva.setText(String.valueOf(sumaTotalSinIva));
                lblTotalConIva.setText(String.valueOf(sumaTotalIva));
                lblTotalGeneral.setText(String.valueOf(sumaTotalIva));
                lblTotalProductoVenta.setText(String.valueOf(model.getRowCount()));
            }
        }
        catch(StockVendidoException e){
            logger.debug("Error:"+e.getMessage());
            lblErrorVenta.setText(e.getMessage());
        }
        catch(StockNoExisteException e){
            logger.debug("Error:"+e.getMessage());
            lblErrorVenta.setText(e.getMessage());
        }
        catch (Exception ex) {
            logger.debug("Error:"+ex.getMessage());
            lblErrorVenta.setText("Error en el sistema");
        }
    }//GEN-LAST:event_bttIngresarCodigoVentaActionPerformed

    private void bttCancelarVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttCancelarVentaActionPerformed
        this.dispose();
    }//GEN-LAST:event_bttCancelarVentaActionPerformed

    private void cmbDescuentoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbDescuentoItemStateChanged

        if (!"".equals(lblTotalConIva.getText())){
            Double total = Double.valueOf(lblTotalConIva.getText());
            String temp = (String) cmbDescuento.getSelectedItem();
            String porcentajeStr = temp.substring(0, temp.length() - 1);
            Double porcentaje = Double.valueOf(porcentajeStr) / 100;
            lblValorDescuento.setText(String.valueOf(Math.ceil(total * porcentaje)));
            lblTotalGeneral.setText(String.valueOf(Math.ceil(total * (1 - porcentaje))));
        }
        
    }//GEN-LAST:event_cmbDescuentoItemStateChanged

    private void bttLimpiarVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttLimpiarVentaActionPerformed
        limpiarFormulario();
    }//GEN-LAST:event_bttLimpiarVentaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentaGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentaGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentaGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentaGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VentaGui().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bttCancelarVenta;
    private javax.swing.JButton bttIngresarCodigoVenta;
    private javax.swing.JButton bttLimpiarVenta;
    private javax.swing.JButton byyAceptarVenta;
    private javax.swing.JComboBox cmbDescuento;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblErrorVenta;
    private javax.swing.JLabel lblIva;
    private javax.swing.JLabel lblTotalConIva;
    private javax.swing.JLabel lblTotalGeneral;
    private javax.swing.JLabel lblTotalProductoVenta;
    private javax.swing.JLabel lblTotalSinIva;
    private javax.swing.JLabel lblValorDescuento;
    private javax.swing.JTable tblListaProductoVenta;
    private javax.swing.JTextField txtCodigoProducto1;
    // End of variables declaration//GEN-END:variables

    private void limpiarFormulario() {
        txtCodigoProducto1.setText("");
        DefaultTableModel model = (DefaultTableModel) tblListaProductoVenta.getModel();
        while (model.getRowCount()>0){
            model.removeRow(0);
        }
        
        lblTotalProductoVenta.setText("");
        lblTotalSinIva.setText("");
        lblIva.setText("");
        lblTotalConIva.setText("");
        cmbDescuento.setSelectedIndex(0);
        lblValorDescuento.setText("");
        lblTotalGeneral.setText("");
        lblErrorVenta.setText("");
    }
}
